//
//  VisitorTableViewController.swift
//  Weibo
//
//  Created by 梁智 on 15/11/22.
//  Copyright © 2015年 lzfree. All rights reserved.
//

import UIKit

class VisitorTableViewController: UITableViewController {

    /// 用户登录标记
    private var userLogin = UserAccountViewModel.sharedUserAccount.userLogin
    
    var visitorView: VisitorView?
    
    override func loadView() {
        
        userLogin ? super.loadView() : setupVisitorView()
    }
    
    private func setupVisitorView() {
        // 替换根视图
        visitorView = VisitorView()
        
        view = visitorView
        
        visitorView?.registerButton.addTarget(self, action: "visitorViewDidRegister", forControlEvents: UIControlEvents.TouchUpInside)
        visitorView?.loginButton.addTarget(self, action: "visitorViewDidLogin", forControlEvents: UIControlEvents.TouchUpInside)
        
        
        navigationItem.leftBarButtonItem = UIBarButtonItem(title: "注册", style: .Plain, target: self, action: "visitorViewDidRegister")
        navigationItem.rightBarButtonItem = UIBarButtonItem(title: "登录", style: .Plain, target: self, action: "visitorViewDidLogin")
    }
    
    func visitorViewDidRegister() {
        print("注册")
    }
    
    func visitorViewDidLogin() {
        let vc = OAuthViewController()
        
        let nav = UINavigationController(rootViewController: vc)
        
        presentViewController(nav, animated: true, completion: nil)
        
    }
    
}